package com.swpu.cbg.cnshop.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.lidroid.xutils.ViewUtils;
import com.swpu.cbg.cnshop.activity.LoginActivity;
import com.swpu.cbg.cnshop.activity.MyApplication;
import com.swpu.cbg.cnshop.bean.User;

/**
 * Created by chenboge on 16/2/18.
 */
public abstract class BaseFragment extends Fragment{


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = createView(inflater, container, savedInstanceState);
        ViewUtils.inject(this, view);

        initToolBar();

        init();

        return view;
    }


    private void initToolBar() {

    }

    public abstract View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState);

    public abstract void init();


    public void startActivity(Intent intent,boolean isNeedLogin){


        if(isNeedLogin){

            User user =MyApplication.getInstanse().getUser();
            if(user !=null){
                super.startActivity(intent);
            }
            else{
                MyApplication.getInstanse().putIntent(intent);
                Intent loginIntent = new Intent(getActivity(), LoginActivity.class);
                super.startActivity(loginIntent);
            }

        }
        else{
            super.startActivity(intent);
        }

    }



}
